package com.sky.demo.java.genericity;

import javafx.util.Pair;
import org.springframework.cglib.core.Local;

import java.time.LocalDate;

public class GenericTest {

    public static void main(String[] args) {
        LocalDate[] brithdays = {
                LocalDate.of(1995, 12, 9),
                LocalDate.of(2000, 2, 2),
                LocalDate.of(2023, 9, 12)
        };
        Pair<LocalDate, LocalDate> result = ArrayAlg.minmax(brithdays);
        System.out.println("result = " + result);
    }

    public static class ArrayAlg{

        public static <T extends Comparable> Pair<T, T> minmax(T[] a){
            if(a == null || a.length == 0){
                return null;
            }

            T min = a[0];
            T max = a[0];

            for(int i = 1; i < a.length; i++){
                if(min.compareTo(a[i]) > 0){
                    min = a[i];
                }
                if(max.compareTo(a[i]) < 0){
                    max = a[i];
                }
            }
            return new Pair<>(min, max);
        }
    }
}
